#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pandas
import datetime


class DateTool:
    """
    日期工具类
    """

    def __init__(self):
        pass

    # date_rule_subtype = 4 , 得到日期的每隔N月的几号
    @staticmethod
    def get_date_every_n_months_m_days(date_i, n_i, day_i):
        import datetime
        year = date_i.year
        month = date_i.month + n_i
        if month > 12:
            year += 1
            month -= 12
        # new_date = datetime.date(year, month, date.day)
        new_date = datetime.date(year, month, day_i)
        return new_date

    @staticmethod
    def get_months_last_day(date_i):
        import calendar
        return calendar.monthrange(date_i.year, date_i.month)[1]

    # @staticmethod
    # def get_now_date_string():
    #     now = datetime.datetime.now()
    #     formatted_time = now.strftime("%Y%m%d-%H%M%S")
    #     # print(formatted_time)
    #     return formatted_time

    @staticmethod
    def get_now_date_string(format_s="%Y%m%d-%H%M%S"):
        now = datetime.datetime.now()
        formatted_time = now.strftime(format_s)
        # print(formatted_time)
        return formatted_time

    @staticmethod
    def format_datetime():
        """返回当前时间的格式化字符串：年月日-时分秒（示例：20250728-181146）"""
        now = datetime.datetime.now()
        formatted = now.strftime("%Y%m%d-%H%M%S")
        return formatted


if __name__ == '__main__':
    date_string = "2022-02-01"
    date_obj = pandas.to_datetime(date_string)
    # date_obj2 = DateTool.get_date_every_n_months_m_days(date_obj, 1, 15)
    # print(str(date_obj2))

    print(DateTool.get_months_last_day(date_obj))
    print(DateTool.get_now_date_string())


